package com.lykj.llw.box.ui.diafrg

import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.animation.Animation
import android.view.animation.RotateAnimation
import com.lykj.lib_base.base.BaseDiaFrg
import com.lykj.llw.box.databinding.DiafrgNetworkBinding
import me.jessyan.autosize.utils.AutoSizeUtils

/**
 * ================================================
 * 网络加载弹窗
 * ================================================
 *
 * @author gosha
 * @date 2023/7/4-17:55
 */
class NetWorkDiaFrg : BaseDiaFrg() {
    lateinit var binding: DiafrgNetworkBinding

    override fun onStart() {
        super.onStart()
        val window = dialog!!.window
        //设置窗口弹出动画
        window!!.setWindowAnimations(0)
        val layoutParams = window.attributes
        layoutParams.apply {
            dimAmount = 0.5f
            gravity = Gravity.CENTER
            width = WindowManager.LayoutParams.WRAP_CONTENT
            height = WindowManager.LayoutParams.WRAP_CONTENT
        }


        if (null != dialog) {
            val dm = DisplayMetrics()
            requireActivity().windowManager.defaultDisplay.getMetrics(dm)
            dialog?.apply {
                setCanceledOnTouchOutside(false)
                window.setGravity(Gravity.CENTER)
                window.setLayout(
                    AutoSizeUtils.dp2px(requireContext(), 180f),
                    AutoSizeUtils.dp2px(requireContext(), 150f)
                )
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = DiafrgNetworkBinding.inflate(layoutInflater)

        initUI()
        initData()
        setListener()
        return binding.root
    }

    override fun initUI() {
        val anim = RotateAnimation(
            0f, 360f, Animation.RELATIVE_TO_SELF,
            0.5f, Animation.RELATIVE_TO_SELF, 0.5f
        )
        anim.duration = 1800
        anim.repeatCount = -1
        binding.ivLoad.startAnimation(anim)
    }

    override fun initData() {
    }

    override fun setListener() {
    }
}